package org.speed.mvc.config;

import org.speed.mvc.filter.LogFilter;
import org.speed.mvc.intecepter.TraceIntecepter;
import org.speed.mvc.servlet.ExtServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class AppConfig {
	
	
	@Configuration
	public class WebMvcConfig implements WebMvcConfigurer {

		@Override
		public void addInterceptors(InterceptorRegistry registry) {
			registry.addInterceptor(new TraceIntecepter()).addPathPatterns("/**");
		}
		
	}
	
	@Bean
	public FilterRegistrationBean logFilter() {
		FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new LogFilter());
		filterRegistrationBean.setName("logFilter");
        filterRegistrationBean.addUrlPatterns("/*");
        return filterRegistrationBean;
	}
	
	@Bean
	public ServletRegistrationBean extServletBean() {
		ServletRegistrationBean extServletBean = new ServletRegistrationBean(new ExtServlet(),"/user");
		return extServletBean;
	}
	
}
